package com.czxy.service.impl;

import com.czxy.dao.GuestDao;
import com.czxy.dao.HealthDao;
import com.czxy.domain.Guest;
import com.czxy.domain.Health;
import com.czxy.domain.HealthVo;
import com.czxy.service.HealthService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zhangmengxiang1@itcast.cn
 * @version 1.0
 * @date 2020/2/11
 */
@Service
public class HealthServiceimpl implements HealthService {

    @Resource
    private HealthDao healthDao;

    @Resource
    private GuestDao guestDao;


    @Override
    public PageInfo<Health> findAllHealthBypage(HealthVo healthVo) {
        PageHelper.startPage(healthVo.getPageNum(),healthVo.getPageSize());
        List<Health> healthList = healthDao.selectAll();
        for (Health health : healthList) {
            Guest guest = guestDao.findOneGuestByRid(health.getRid());
            health.setGuest(guest);
        }
        return new PageInfo<>(healthList);
    }

    @Override
    public void updateHealth(Health health) {
        healthDao.updateByPrimaryKeySelective(health);
    }

    @Override
    public Health findOneByhid(Integer hid) {
        return healthDao.selectByPrimaryKey(hid);
    }

    @Override
    public void delhealthbyhid(Integer hid) {
        healthDao.deleteByPrimaryKey(hid);
    }
}
